#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL gcd(LL a, LL b)
{
	return b == 0 ? a : gcd(b, a % b);
}

LL lcm(LL a, LL b)
{
	return a * b / gcd(a, b);
}

int main()
{
	LL t; cin >> t;
	while(t --)
	{
		LL n, a, b; cin >> n >> a >> b;
		LL t = n / a + n / b;
		t -= n / lcm(a, b);
		cout << t << endl;
	}
	return 0;
}